<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.tjsinfo.tjsoa.workplan.sqlmap.UserInfo"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>"/>
    
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>粮油集团办公自动化协作平台</title>
<link href="style/txlz7.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="<%=basePath %>ajaxFramework/ext-2.1/resources/css/ext-all.css" />
<script type="text/javascript" src="<%=basePath %>ajaxFramework/ext-2.1/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="<%=basePath %>ajaxFramework/ext-2.1/ext-all.js"></script>
<script type="text/javascript" src="<%=basePath %>ajaxFramework/jQuery/jquery.js"></script>
<script type="text/javascript" src="<%=basePath %>js/common/global/pageControl.js"></script> 
<script >
function left()
{
	$("#list2  input[name=checkbox2]").each(function(){
		if($(this).attr('checked') == true)
		{
			$(this).parent().remove();
		}
	});
	
}
function submit1()
{
	
	var checkbox2 = document.getElementsByName('checkbox2');
		
	for(var a = 0; a<=checkbox2.length; a++)
	{
		var check1 = checkbox2[a];
		if(check1 != undefined)
		{
			check1.setAttribute('checked',true);
		}
		
	}
	msg();
	document.form1.submit();
}
</script>

<script type="text/javascript">
 	var selectusercheckwin,selectusercheckididtager='',userchecksm,checkoldnode=0, 
selectuserchecknametager='',selectuserchecknodetager = '',selectcheckusersort='',
checkuserid=new Ext.data.Store();
 	function initusercheck(){
 	 Ext.BLANK_IMAGE_URL=Ext.get('basePath').getValue()+"ajaxFramework/ext-2.1/resources/images/default/s.gif";	
	 var url = Ext.get('basePath').getValue()+'tjsinfo/tjsoa/system/departmenttree.do';
	 var load = new Ext.tree.TreeLoader({
	 	dataUrl:url
	 });
	 var root = new Ext.tree.AsyncTreeNode({
	 	id:'0',
	 	text:'天津电子计算机研究所'
	 })
	 var tree = new Ext.tree.TreePanel({
	 		x:5,
	 		y:5,	        
        	autoScroll: true,
        	animate: true,
        	containerScroll: true,
        	border: true,
	        loader:load,
	         height:300,
	        width:200
	    });
	tree.setRootNode(root); 
	tree.on('click',function(node){
		selectusercheckarray()
		selectcheckusersort.load({
			params:{departmentid:node.id},
			callback:function(r,options,success){
				for(var i=0;i<r.length;i++)
				{
					var index = checkuserid.findBy(function(record,id){
						if(record.data.nodeid == node.id && record.data.userId ==  r[i].data.userId)
						{
							userchecksm.selectRecords([r[i]],true);
						}
					});
				}
			} 
		});
		checkoldnode=node.id;
	})
	/**
	 * 用户列表
	 */
	var userlisturl = Ext.get('basePath').getValue()+'tjsinfo/tjsoa/system/selectUserByDepartmentList.do'
	selectcheckusersort = new Ext.data.JsonStore({
		url:userlisturl,
		fields:['userId','uuid','userName']
	});
	userchecksm  = new Ext.grid.CheckboxSelectionModel({
		handleMouseDown:Ext.emptyFn
	});
	var cm = new Ext.grid.ColumnModel([
		userchecksm,
		{header: "用户名", width: 75, dataIndex: 'userName',menuDisabled : true},
		{header: "userId", width: 75, dataIndex: 'userId',menuDisabled : true,hidden:true},
		{header: "uuid", width: 75, dataIndex: 'uuid',menuDisabled : true,hidden:true}
	]);
	var grid = new Ext.grid.GridPanel({
		x:205,
	 	y:5,
		cm:cm,
		sm:userchecksm,
		width:100,
		height:300,
		store:selectcheckusersort,
		border: true,
	   	viewConfig:{
			forceFit:true	
		}
	});
	selectusercheckwin = new Ext.Panel({
		layout:'absolute',
		title:'人员选择',
		width:320,
		height:300,
		renderTo:'tree',
		items:[tree,grid]
	})
}
function right(){
	var userid='',username='',nodeid='';
	selectusercheckarray();
	checkuserid.each(function(record){
					userid+=record.data.userId+",";
					username+=record.data.userName+",";
					nodeid+=record.data.nodeid+",";
					if(document.getElementById(record.data.userId) ==null)
					{
						$("<li id='"+record.data.userId+"'><input type='checkbox' name='checkbox2' value='"+record.data.userId+"' />"+record.data.userName+"</li>")
					.appendTo("#list2");	
					}										
	})
}
/**
 * 添加数组中的数据
 * @param {} id
 */
function selectusercheckarray(){
	clearusercheckarray();
	var rlolesarray,nouserselectaray,index;
	rlolesarray = userchecksm.getSelections();
	for(var i =0;i<rlolesarray.length;i++)
	{
		index = checkuserid.findBy(function(record,id){
			 return record.data.nodeid == checkoldnode && rlolesarray[i].data.userId == record.data.userId	
		})
		
		if(index == -1 ||checkuserid.getCount() ==0)
		{
			checkuserid.addSorted(new Ext.data.Record({
				nodeid:checkoldnode,
				userId:rlolesarray[i].data.userId,
				userName:rlolesarray[i].data.userName
			}))
		}
	}
	
}
/**
 * 从数组中清除未被选中的数据
 */
function clearusercheckarray(){
	selectcheckusersort.each(function(r){
		if(userchecksm.isSelected(r) == false)
		{
			var index =	checkuserid.findBy(function(record,id){
				return  record.data.nodeid == checkoldnode && record.data.userId == r.data.userId
			})
			checkuserid.remove(checkuserid.getAt(index));
		}
	})
	
}
 </script>
  </head>
  
  <body onload="initusercheck()">
  <%
  	List list = (List)request.getAttribute("definenot");
  	List list2 = (List)request.getAttribute("define");
  	String type = (String)request.getAttribute("type");
  %>
  <form action="<%=basePath%>tjsinfo/tjsoa/workplan/addWorkPlanDefine.do" name="form1" method="post">
  <input type="hidden" name="type" value="<%=type %>"/>
  
  
  <div id="right" style="height: 93%">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" >
          <tr>
            <td background="images/contacttitle01.gif" width="28" height="26"></td>
            <td class="td1px">设置默认上报用户</td>
            <td background="images/contacttitle03.gif" width="72" height="26">&nbsp;</td>
          </tr>
      </table>
      <div class="contact_content">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td background="images/bghui01.gif" width="99%" height="72">&nbsp;</td>
          </tr>
          <tr>
            <td align="center">
             <table width="496" height="100%"border="0" cellpadding="0" cellspacing="0" >
               <tr>
                 <td rowspan="2">
                   <table width="172" border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        
                      </tr>
                      <tr>
                       
                      </tr>
                      <tr>
                        <td> <td align="left"><div id="tree"  style="height: 300px;width:320px;border: 1px #AFACAC solid;" >
                                          
                       </div> </td>
                      </tr>
                   </table>                 </td>
                 <td><a href="javascript:right()" ><img src="images/tongbu_07.gif" /></a>                 </td>
                 <td rowspan="2">
                   <table width="197" border="0" cellpadding="0" cellspacing="0">
                      <tr>
                      
                      </tr>
                      <tr>
                        <td >
                        <div class="tongbutab02" style="height: 300px;width:95%; border: 1px #AFACAC solid;">
                         <ul id="list2">
                           <%
                           		Iterator iterator = list2.iterator();
                         		while(iterator.hasNext())
                         		{
                         			UserInfo userInfo = (UserInfo)iterator.next();
                         	%>
                         		<li id="<%=userInfo.getId()%>"><input type="checkbox" name="checkbox2" value="<%=userInfo.getId()%>" /><%=userInfo.getUsername()%></li>
                         	<% 		
                         			
                         		}
                         	%>
                         </ul>
                        </div>                        </td>
                      </tr>
                      <tr>
                        <td ></td>
                      </tr>
                   </table>                 </td>
               </tr>
               <tr>
                 <td><a  href="javascript:left()"  ><img src="images/tongbu_08.gif" /></a></td>
               </tr>
               <tr>
                 <td colspan="3"><br /><br /><a href="javascript:submit1()" ><img src="images/qued.gif" /></a>&nbsp;
                 <a href="<%=basePath%>tjsinfo/tjsoa/workplan/workPlanlistmode.do" ><img src="images/fanhuiab.gif" /></a></td>
               </tr>
             </table>
            </td>
          </tr>
      </table>
      </div>
</div>
 <input id="basePath" value="<%=basePath%>" type="hidden"/>
</form>
	<%
	if(request.getAttribute("start") !=null)
	{
%>
	<script >
		Ext.onReady(function(){
			Ext.MessageBox.alert("系统消息","默认审批人设置成功!");
		});
	</script>
<% 		
	}
%>
  </body>
</html>
